package com.baohulu.baohulu.activity.account;

import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.baohulu.baohulu.R;
import com.baohulu.baohulu.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 登录和注册界面，为了复用界面使用状态模式进行了设计，后续如果需要可分离成两个单独的 Activity
 */
public class AccountActivity extends BaseActivity {

    @BindView(R.id.et_phone_number)
    EditText etPhoneNumber;
    @BindView(R.id.et_password)
    EditText etPassword;
    @BindView(R.id.login)
    Button btnLogin;
    @BindView(R.id.tv_register_account)
    TextView tvRegisterAcc;
    @BindView(R.id.tv_forget_password)
    TextView tvForgetPassword;
    @BindView(R.id.hint_text)
    TextView tvHintText;
    @BindView(R.id.et_confirm_password)
    EditText etConfirmPassword;
    @BindView(R.id.label_confirm_password)
    TextView tvConfirmPassword;

    private AccountState mAccountState;//记录当前界面状态是登录还是注册，默认为登录状态

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_account);
        ButterKnife.bind(this);
        mAccountState = new LoginState(this);
    }


    @OnClick(R.id.tv_register_account)
    public void onRegisterBtnClick() {
        toggleState();
    }

    /**
     * 切换页面状态：注册/登录
     */
    public void toggleState() {
        mAccountState = mAccountState instanceof LoginState ? new RegisterState(this) : new LoginState(this);
    }

    @OnClick(R.id.login)
    public void resolveInput() {
        mAccountState.resolveInput();
    }

    @OnClick(R.id.tv_forget_password)
    public void forgetPassword() {
        mAccountState.forgetPassword();
    }


}
